package com.wesley.netty.chat.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

/**
 * <p>
 *
 * </p>
 *
 * @author Wesley
 * Created by 2018/08/29
 */
public class SimpleChatServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        // 分包
//        pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
        // 向pipeline添加解码器
        pipeline.addLast("decoder", new StringDecoder());
        // 添加编码器
        pipeline.addLast("encoder", new StringEncoder());
        // 业务处理器
        pipeline.addLast("handler", new SimpleChatServerHandler());
    }
}
